import React, { Component, lazy, Suspense } from 'react';
import { Route, Redirect, Switch } from 'react-router-dom'
// import Index from './views/Index'
// import Login from './views/Login'
// import Register from './views/Register'
// import NotFound from './views/NotFound'
//路由懒加载
let Index = lazy(() => import('./views/Index'))
let Login = lazy(() => import('./views/Login'))
let Register = lazy(() => import('./views/Register'))
let NotFound = lazy(() => import('./views/NotFound'))
let Detail = lazy(() => import('./views/Detail'))
let Findgood = lazy(() => import('./views/Findgood'))
let Mycollect = lazy(() => import('./views/Mycollect'))
class App extends Component {
    render() {//渲染组件到视图
        return (
            <div>
                <Suspense fallback={<div>loading...</div>}>
                    <Switch>
                        <Route path="/index" component={Index} />
                        <Route path='/login' component={Login} />
                        <Route path='/register' component={Register} />
                        <Route path='/detail' component={Detail} />
                        <Route path='/findgood' component={Findgood} />
                        <Route path='/mycollect' component={Mycollect} />
                        <Redirect exact from='/' to='/index' />
                        <Route path='*' component={NotFound} />
                    </Switch>
                </Suspense>
            </div>
        );
    }
}

export default App;